package com.yzk.user.service.impl;

import java.util.List;

import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import javax.persistence.Query;

import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.yzk.user.model.SysUser;
import com.yzk.user.service.IUserSer;

@Transactional(readOnly=false)
@Service
public class UserSerImp implements IUserSer {

	private EntityManager entityManager;
	
	@Override
	public void save(SysUser entity) {
		entityManager.persist(entity);
		System.out.println("save sucessful!!!");
	}
	
	@SuppressWarnings("unchecked")
	public List<SysUser> listUser() {
		Query query = entityManager.createQuery("select u from SysUser u") ;
		return query.getResultList();
	}
	
	public SysUser findById(Integer id) {
		SysUser user = entityManager.find(SysUser.class, id) ;
		return user;
	}

	public EntityManager getEntityManager() {
		return entityManager;
	}
	

	@PersistenceContext
	public void setEntityManager(EntityManager entityManager) {
		this.entityManager = entityManager;
	}
	
}
